﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapLibrary.Utility
{
    /// <summary>
    /// Handles game states and state switching.
    /// </summary>
    public class GameStateManager
    {
        #region singleton implemenation
        private static GameStateManager instance;

        private GameStateManager()
        {
            currState = GameState.MainMenu;
        }

        public static GameStateManager Instance
        {
            get
            {
                if (instance == null)
                    instance = new GameStateManager();

                return instance;
            }
        }
        #endregion

        private GameState currState;

        public delegate void StateChangeDelegate();

        public event StateChangeDelegate OnStateChange;

        public enum GameState
        {
            MainMenu,
            Paused,
            InGame,
            GameOver,
            Quitting
        };

        /// <summary>
        /// The current game state.
        /// </summary>
        public GameState CurrentState
        {
            get { return currState; }
        }

        /// <summary>
        /// Switch to a new state, notify classes as necessary.
        /// </summary>
        /// <param name="newState"></param>
        public void SwitchState(GameState newState)
        {
            currState = newState;

            if (OnStateChange != null)
                OnStateChange();
        }

        public bool IsCurrentState(GameState state)
        {
            return currState == state;
        }
    }
}
